package com.wiscamp.ninechapters.problems.infrastructure.po.sheets;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.wiscamp.ninechapters.ddd.PersistenceObject;
import jakarta.persistence.*;
import lombok.Data;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;

/**
 * 答题卡明细
 */
@Entity
@Table(name = "sheet_details")
@Data
public class SheetDetailPO implements PersistenceObject {
    @Serial
    private static final long serialVersionUID = 3688577969769601547L;

    /**
     * 明细编号
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(insertable = false, name = "detail_id", nullable = false)
    private long detailId = 0;


    /**
     * 答题卡编号
     */
    @Column(name = "sheet_id", nullable = false)
    private long sheetId;

    /**
     * 题编号
     */
    @Column(name = "problem_id", nullable = false)
    private long problemId = 0;

    /**
     * 问题编号
     */
    @Column(name = "question_id", nullable = false)
    private long questionId = 0;


    /**
     * 解题方法 (存储解题步骤图片URL)
     */
    @Column(name = "solution_url")
    private String solutionUrl = "";

    /**
     * 问题获得分数
     */
    @Column(name = "gain_score", nullable = false)
    private double gainScore = 0;

    /**
     * 是否评分
     */
    @Column(name = "scored", nullable = false)
    private boolean scored = false;

    /**
     * 是否批改
     */
    @Column(name = "reviewed", nullable = false)
    private boolean reviewed = false;

    /**
     * 批改次数
     */
    @Column(name = "review_count", nullable = false)
    private int reviewCount = 0;

    /**
     * 做题开始时间
     */
    @Column(name = "question_begin_time", nullable = false)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime questionBeginTime;

    /**
     * 做题结束时间
     */
    @Column(name = "question_end_time")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime questionEndTime;

    /**
     * 答题秒数
     */
    @Column(name = "answering_seconds", nullable = false)
    private int answeringSeconds = 0;

    /**
     * 语料编号
     */
    @Column(name = "corpus_id", nullable = false)
    private long corpusId = 0;

    /**
     * 正确状态 0-错误 1-全部正确 2-部分正确
     */
    @Column(name = "correct_status", nullable = false)
    private int correctStatus = 0;

    /**
     * 答题卡明细文本扩展 (记录多结果)
     */
    //@JoinColumn(name = "sheet_detail_id", nullable = false, insertable = false, updatable = false)
    //@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @Transient
    private Collection<SheetAnswerPO> sheetAnswers = new ArrayList<>();

}